/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-10-14     yc       the first version
 */

#include "bsp.h"



static int bsp_spi_flash_init(void)
{
    FLASH_SPI_NSS_CLK();

    rt_hw_spi_device_attach(FLASH_SPI_DEVICE,FLASH_SPI_DEVICE_NUMBER,FLASH_SPI_NSS_GPIO_PORT,FLASH_SPI_NSS_GPIO_PIN);

    if(RT_NULL == rt_sfud_flash_probe(FLASH_SPI_DEVICE_NAME,FLASH_SPI_DEVICE_NUMBER))
    {
        return -RT_ERROR;
    }

    return RT_EOK;
}
INIT_COMPONENT_EXPORT(bsp_spi_flash_init);

void bsp_w25q128_init(void)
{
    struct rt_spi_configuration  w28q128_cfg;
    struct rt_spi_device *spi_dev_w25q;
    w28q128_cfg.mode = RT_SPI_MSB | RT_SPI_MASTER | RT_SPI_MODE_0 ;
    w28q128_cfg.max_hz = 50 * 1000 *1000;
    w28q128_cfg.data_width = 8;

    spi_dev_w25q = (struct rt_spi_device *)rt_device_find(FLASH_SPI_DEVICE_NUMBER);
    if(  RT_EOK == rt_spi_configure(spi_dev_w25q, &w28q128_cfg))
    {
        rt_kprintf("rt_spi_configure is ok\n");
    }


}
